package com.lishe.lishe.lishe.module.business.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.base.BaseActivity;
import com.lishe.lishe.lishe.module.business.fragment.ShowGiftFragment;
import com.lishe.lishe.lishe.module.business.fragment.ShowGiftMeFragment;
import com.lishe.lishe.lishe.module.commonclass.FragmentAdapter;
import java.util.LinkedList;

/**
 * Created by shino on 2017/10/18.
 * 企业圈
 */

public class BusinessActivity extends BaseActivity implements View.OnClickListener {
    private Button showGift;
    private Button callBack;
    private TextView title;
    private TabLayout tabLayout;
    private ViewPager viewpager;
    private FragmentAdapter fragmentAdapter;
    private LinkedList<String> titles = new LinkedList<>();
    private LinkedList<Fragment> fragments = new LinkedList<>();

    public static void jump(Activity activity) {
        Intent intent = new Intent(activity, BusinessActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business);
        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        initFragment();
        initView();
    }

    private void initView() {
        title = findViewById(R.id.title_text_title);
        callBack = findViewById(R.id.title_left_button);
        showGift = findViewById(R.id.title_rigth_button);
        title.setText(R.string.show_gift);
        showGift.setBackground(getResources().getDrawable(R.mipmap.show_gift_icon));
        showGift.setVisibility(View.VISIBLE);
        tabLayout = findViewById(R.id.tabLayout);
        viewpager = findViewById(R.id.viewPager);
        viewpager.setAdapter(fragmentAdapter);
        tabLayout.setupWithViewPager(viewpager);
        setListener();
    }

    private void setListener() {
        callBack.setOnClickListener(this);
        showGift.setOnClickListener(this);

    }

    private void initFragment() {
        titles.clear();
        fragments.clear();
        titles.add("单品");
        titles.add("详情");
        fragments.add(ShowGiftFragment.newInstanse());
        fragments.add(ShowGiftMeFragment.newInstanse());
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_left_button:
                finish();
                break;
            case R.id.title_rigth_button:
                AddShowGiftActivity.jump(BusinessActivity.this);
                break;
        }
    }
}
